package com.zc.topmod.impl;

import com.zc.topmod.enumer.RoadEvaLevelEnum;
import lombok.extern.slf4j.Slf4j;

/**
 * Created by zhucan on 19/2/3.
 */
@Slf4j
public class BaseRebModCalFormulaImpl {

    final Double e=2.718281828459;

    /**
     * 基顶当量回弹模量实测值计算
     * @param surfaceThickness
     * @param surfaceModulus
     * @param frequency
     * @return
     */
    public Double calForm(Double surfaceThickness,Double surfaceModulus,Double frequency) {
        Double result=0.00;
        if (Double.compare(surfaceThickness,0.14)==0) { // 014
            result= (0.0035*Math.pow(surfaceModulus*0.001,0.0841)*Math.pow(e,((-0.0081)*Math.log(surfaceModulus*0.001)+0.472)*frequency))*1000;
        } else if (Double.compare(surfaceThickness,0.15)==0) { // 015
            result= (0.0035*Math.pow(surfaceModulus*0.001,0.0841)*Math.pow(e,((-0.007)*Math.log(surfaceModulus*0.001)+0.4718)*frequency))*1000;
        } else if (Double.compare(surfaceThickness,0.16)==0) { // 016
            result= (0.0035*Math.pow(surfaceModulus*0.001,0.0841)*Math.pow(e,((-0.007)*Math.log(surfaceModulus*0.001)+0.4715)*frequency))*1000;
        } else if (Double.compare(surfaceThickness,0.17)==0) { // 017
            result= (0.0036*Math.pow(surfaceModulus*0.001,0.0743)*Math.pow(e,((-0.007)*Math.log(surfaceModulus*0.001)+0.4713)*frequency))*1000;
        } else if (Double.compare(surfaceThickness,0.18)==0) { // 018
            result= (0.0036*Math.pow(surfaceModulus*0.001,0.0695)*Math.pow(e,((-0.006)*Math.log(surfaceModulus*0.001)+0.4711)*frequency))*1000;
        } else if (Double.compare(surfaceThickness,0.19)==0) { // 019
            result= (0.0036*Math.pow(surfaceModulus*0.001,0.0695)*Math.pow(e,((-0.006)*Math.log(surfaceModulus*0.001)+0.4708)*frequency))*1000;
        } else if (Double.compare(surfaceThickness,0.20)==0) { // 020
            result= (0.0036*Math.pow(surfaceModulus*0.001,0.0569)*Math.pow(e,((-0.006)*Math.log(surfaceModulus*0.001)+0.4707)*frequency))*1000;
        } else if (Double.compare(surfaceThickness,0.21)==0) { // 021
            result= (0.0036*Math.pow(surfaceModulus*0.001,0.0523)*Math.pow(e,((-0.006)*Math.log(surfaceModulus*0.001)+0.4705)*frequency))*1000;
        } else if (Double.compare(surfaceThickness,0.22)==0) { // 022
            result= (0.0037*Math.pow(surfaceModulus*0.001,0.0468)*Math.pow(e,((-0.006)*Math.log(surfaceModulus*0.001)+0.4703)*frequency))*1000;
        } else if (Double.compare(surfaceThickness,0.23)==0) { // 023
            result= (0.0037*Math.pow(surfaceModulus*0.001,0.0481)*Math.pow(e,((-0.005)*Math.log(surfaceModulus*0.001)+0.4701)*frequency))*1000;
        } else if (Double.compare(surfaceThickness,0.24)==0) { // 024
            result= (0.0037*Math.pow(surfaceModulus*0.001,0.0396)*Math.pow(e,((-0.005)*Math.log(surfaceModulus*0.001)+0.47)*frequency))*1000;
        } else if (Double.compare(surfaceThickness,0.25)==0) { // 025
            result= (0.0037*Math.pow(surfaceModulus*0.001,0.0424)*Math.pow(e,((-0.005)*Math.log(surfaceModulus*0.001)+0.4698)*frequency))*1000;
        } else if (Double.compare(surfaceThickness,0.26)==0) { // 026
            result= (0.0037*Math.pow(surfaceModulus*0.001,0.0424)*Math.pow(e,((-0.005)*Math.log(surfaceModulus*0.001)+0.4697)*frequency))*1000;
        } else if (Double.compare(surfaceThickness,0.27)==0) { // 027
            result= (0.0038*Math.pow(surfaceModulus*0.001,0.0379)*Math.pow(e,((-0.005)*Math.log(surfaceModulus*0.001)+0.4695)*frequency))*1000;
        } else if (Double.compare(surfaceThickness,0.28)==0) { // 028
            result= (0.0038*Math.pow(surfaceModulus*0.001,0.0296)*Math.pow(e,((-0.005)*Math.log(surfaceModulus*0.001)+0.4694)*frequency))*1000;
        } else if (Double.compare(surfaceThickness,0.29)==0) { // 029
            result= (0.0038*Math.pow(surfaceModulus*0.001,0.0288)*Math.pow(e,((-0.004)*Math.log(surfaceModulus*0.001)+0.4692)*frequency))*1000;
        } else if (Double.compare(surfaceThickness,0.30)==0) { // 030
            result= (0.0038*Math.pow(surfaceModulus*0.001,0.0288)*Math.pow(e,((-0.004)*Math.log(surfaceModulus*0.001)+0.4692)*frequency))*1000;
        }
        return result;
    }

    /**
     * 计算弯沉
     * @param disOutTireEnum
     * @param deflection
     * @return
     */
    public Double calFormWc( Double disOutTireEnum, Double deflection) {
        Double result=0.00;

        if (Double.compare(disOutTireEnum,0.4)==0) { // 04
            result= 0.8791*deflection-0.0087;
        } else if (Double.compare(disOutTireEnum,0.6)==0) { // 06
            result= 1.092*deflection-0.0188;
        } else if (Double.compare(disOutTireEnum,0.8)==0) { // 08
            result= 1.1116*deflection-0.0487;
        }

        return result;
    }

    /**
     * 计算应变
     * @param disOutTireEnum
     * @param et
     * @param strain
     * @return
     */
    public Double calFormYb( Double disOutTireEnum,Double et, Double strain) {
        Double result=0.00;

        if (Double.compare(disOutTireEnum,0.4)==0) { // 04
            log.info("s0公式1");
            result= 0.9765*Math.pow(e,0.0007*et)*strain*(-0.001)+(0.0979*Math.log(et)-0.8138);
        } else if (Double.compare(disOutTireEnum,0.6)==0) { // 06
            log.info("s0公式2");
            result= 0.9492*Math.pow(e,0.0008*et)*strain*(-0.001)+(0.1020*Math.log(et)-0.8407);
        } else if (Double.compare(disOutTireEnum,0.8)==0) { // 08
            log.info("s0公式3");
            result= 1.0079*Math.pow(e,0.0002*et)*strain*(-0.001)+(0.0783*Math.log(et)-0.6968);
        }

        return result;
    }

    /**
     * 车轮作用位置处路表弯沉与静弯沉转换关系
     * @param s0
     * @param roadFlatness
     * @param drivingSpeed
     * @return
     */
    public Double calFormJwc(Double s0,Double roadFlatness,Double drivingSpeed) {
        Double result=0.00;
        result=s0/(1+11.5*0.001*roadFlatness/0.6*Math.sqrt(drivingSpeed));
        return result;
    }

    /**
     * 计算SSI
     * @param designAllowDef
     * @param jwc
     * @return
     */
    public Double calFormSsi(Double designAllowDef,Double jwc) {
        designAllowDef=Math.abs(designAllowDef);
        jwc=Math.abs(jwc);
        Double result=0.00;
        result=designAllowDef/jwc;
        return Math.abs(result);
    }

    /**
     * 计算PSSI
     * @param ssi
     * @return
     */
    public Double calFormPssi(Double ssi) {
        Double result=0.00;
        result=100/(1+15.71*Math.pow(e,(-5.19)*ssi));
        return result;
    }

    /**
     * SSI道路等级
     * @param roadGradeEnum
     * @param ssi
     * @return
     */
    public String judgeSsiRoadEvaLevel(String roadGradeEnum,Double ssi) {
        String result=null;
        int resultlevel=99;
        // SSI判断
        if (roadGradeEnum.equals("0")||roadGradeEnum.equals("1")) {
            if (Double.compare(ssi,1.0)>=0) {
                resultlevel=0;
            } else if (Double.compare(ssi,0.83)>=0 && Double.compare(ssi,1.0)<=0) {
                resultlevel=1;
            } else if (Double.compare(ssi,0.66)>=0 && Double.compare(ssi,0.83)<=0) {
                resultlevel=2;
            } else if (Double.compare(ssi,0.5)>=0 && Double.compare(ssi,0.66)<=0) {
                resultlevel=3;
            } else {
                resultlevel=4;
            }
        } else if (roadGradeEnum.equals("2")) {
            if (Double.compare(ssi,0.83)>=0) {
                resultlevel=0;
            } else if (Double.compare(ssi,0.66)>=0 && Double.compare(ssi,0.83)<=0) {
                resultlevel=1;
            } else if (Double.compare(ssi,0.5)>=0 && Double.compare(ssi,0.66)<=0) {
                resultlevel=2;
            } else if (Double.compare(ssi,0.3)>=0 && Double.compare(ssi,0.5)<=0) {
                resultlevel=3;
            } else {
                resultlevel=4;
            }
        }



        result=String.valueOf(resultlevel);
        result=RoadEvaLevelEnum.getValue(result);

        return result;
    }

    /**
     * PSSI道路等级
     * @param roadGradeEnum
     * @param pssi
     * @return
     */
    public String judgePssiRoadEvaLevel(String roadGradeEnum,Double pssi) {
        String result=null;
        int resultlevelPssi=99;

        // PSSI判断
        if (Double.compare(pssi,91.9)>=0) {
            resultlevelPssi=0;
        } else if (Double.compare(pssi,82.6)>=0 && Double.compare(pssi,91.9)<=0) {
            resultlevelPssi=1;
        } else if (Double.compare(pssi,66.2)>=0 && Double.compare(pssi,82.6)<=0) {
            resultlevelPssi=2;
        } else if (Double.compare(pssi,45.8)>=0 && Double.compare(pssi,66.2)<=0) {
            resultlevelPssi=3;
        } else {
            resultlevelPssi=4;
        }


        result=String.valueOf(resultlevelPssi);
        result=RoadEvaLevelEnum.getValue(result);

        return result;
    }


    public static void main(String[] args) {
        BaseRebModCalFormulaImpl baseRebModCalFormulaImpl= new BaseRebModCalFormulaImpl();
        System.out.println("计算结果:"+String.valueOf(baseRebModCalFormulaImpl.calForm(0.14,4000.00,12.73)));
        System.out.println("计算结果:"+baseRebModCalFormulaImpl.calFormYb(0.4,1387.0928398610633,12.335));

        return;
    }
}
